package com.scau.data.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.scau.data.entity.ReturnGoodsDO;
import com.scau.database.entity.storemanager.ReturnDTO;
import com.scau.database.enums.IsFinishedEnum;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ReturnGoodsMapper extends BaseMapper<ReturnGoodsDO> {
    final String NOT_FINISHED_STR = "0"; // 未完成
    @Select("SELECT \n" +
            "bar_code,\n" +
            "return_goods.`count` `count`,\n" +
            "return_goods.type,\n" +
            "return_goods.id deal_id,\n" +
            "return_goods.service_id service_id,\n" +
            "custormer_service.`name` service_name,\n" +
            "can_resell can_resell,\n" +
            "`order`.factory_id factory_id,\n" +
            "factory.`name` factory_name, \n" +
            "return_goods.finishied finished \n" +
            "FROM\n" +
            "(SELECT id shelf_id,bar_code,warehouse_id\n" +
            "FROM `shelf_ok`\n" +
            "WHERE warehouse_id = #{warehouseId}\n" +
            "UNION \n" +
            "SELECT id,bar_code,warehouse_id \n" +
            "FROM shelf_over\n" +
            "WHERE warehouse_id =#{warehouseId}) AS t1\n" +
//
//            "JOIN order_line USING(bar_code)\n" +
            "join (SELECT * FROM order_line\n" +
            "GROUP BY(bar_code)\n" +
            ") as t2 \n" +
            " USING(bar_code) \n"+

            "JOIN `order` USING(order_number)\n" +
            "JOIN factory ON `order`.factory_id = factory.id \n"+
            "JOIN shop_line USING(bar_code,shelf_id)\n" +
            "JOIN return_goods USING(shop_id,bar_code,shelf_id)\n" +
            "LEFT JOIN custormer_service ON(return_goods.service_id = custormer_service.id)\n" +
            "WHERE finishied ="+NOT_FINISHED_STR)
    public List<ReturnDTO> getNeedDealReturnInfos(Integer warehouseId);



    @Select("SELECT warehouse_id FROM shelf_ok WHERE id = #{shelfId}\n" +
            "UNION\n" +
            "SELECT warehouse_id FROM shelf_over WHERE id = #{shelfId}")
    Integer getWarehouseId(Long shelfId);
}
